package com.ruoyi.coffee.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.coffee.domain.Users;
import com.ruoyi.coffee.mapper.UsersMapper;
import com.ruoyi.coffee.vo.CategoryVo;
import com.ruoyi.coffee.vo.ProductsVo;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.coffee.mapper.CategoriesMapper;
import com.ruoyi.coffee.domain.Categories;
import com.ruoyi.coffee.service.ICategoriesService;

import javax.annotation.Resource;

/**
 * 咖啡分类Service业务层处理
 *
 * @author dxj
 * @date 2024-12-29
 */
@Service
public class CategoriesServiceImpl extends ServiceImpl<CategoriesMapper, Categories> implements ICategoriesService {

    @Resource
    private CategoriesMapper categoriesMapper;

    /**
     * 查询咖啡分类
     *
     * @param categoryId 咖啡分类主键
     * @return 咖啡分类
     */
    @Override
    public Categories selectCategoriesByCategoryId(Long categoryId) {
        return categoriesMapper.selectCategoriesByCategoryId(categoryId);
    }

    /**
     * 查询咖啡分类列表
     *
     * @param categories 咖啡分类
     * @return 咖啡分类
     */
    @Override
    public List<Categories> selectCategoriesList(Categories categories) {
        return categoriesMapper.selectCategoriesList(categories);
    }

    /**
     * 新增咖啡分类
     *
     * @param categories 咖啡分类
     * @return 结果
     */
    @Override
    public int insertCategories(Categories categories) {
        return categoriesMapper.insertCategories(categories);
    }

    /**
     * 修改咖啡分类
     *
     * @param categories 咖啡分类
     * @return 结果
     */
    @Override
    public int updateCategories(Categories categories) {
        return categoriesMapper.updateCategories(categories);
    }

    /**
     * 批量删除咖啡分类
     *
     * @param categoryIds 需要删除的咖啡分类主键
     * @return 结果
     */
    @Override
    public int deleteCategoriesByCategoryIds(Long[] categoryIds) {
        return categoriesMapper.deleteCategoriesByCategoryIds(categoryIds);
    }

    /**
     * 删除咖啡分类信息
     *
     * @param categoryId 咖啡分类主键
     * @return 结果
     */
    @Override
    public int deleteCategoriesByCategoryId(Long categoryId) {
        return categoriesMapper.deleteCategoriesByCategoryId(categoryId);
    }

    /**
     * 获取咖啡分类列表
     *
     * @return
     */
    @Override
    public List<CategoryVo> getCategoryList() {
        List<CategoryVo> list = categoriesMapper.selectList(new LambdaQueryWrapper<Categories>().select(Categories::getCategoryId, Categories::getCategoryName)).stream()
                .map(item -> {
                    CategoryVo categoryVo = new CategoryVo();
                    BeanUtils.copyProperties(item, categoryVo);
                    return categoryVo;
                }).sorted((o1, o2) -> o1.getCategoryId().compareTo(o2.getCategoryId())).collect(Collectors.toList());
        return list;
    }
}
